package com.neusoft.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.neusoft.mapper.RedenvMapper;
import com.neusoft.po.Redenv;
import com.neusoft.service.RedenvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class RedenvServiceImpl implements RedenvService {

    @Autowired
    private RedenvMapper redenvMapper;

    @Override
    public int saveOneRedenvByUserId(Redenv redenv){
        double random = Math.random()*5;// 生成[0.0, 1.0)之间的随机数
        BigDecimal balance = new BigDecimal(random);
        return redenvMapper.saveOneRedenvByUserId(redenv.getUserId(),balance);
    }

    @Override
    public List<Redenv> getAllRedenvsByUserId(String userId){
        return redenvMapper.getAllRedenvsByUserId(userId);
    }

    @Override
    public int useRedenvByRedenvId(Integer redenvId){
        return redenvMapper.useRedenvByRedenvId(redenvId);
    }

    @Override
    public Redenv getRedenvByRedenvId(Integer redenvId){
        return redenvMapper.getRedenvByRedenvId(redenvId);
    }
}
